<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>基本资料</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/layui/lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="/layui/css/public.css" media="all">
    <style>
        .layui-form-item .layui-input-company {width: auto;padding-right: 10px;line-height: 38px;}


         .layui-form-label{
             width: 90px;
         }
    </style>
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">
        <div class="layui-form layuimini-form">
            <input type="hidden" value="${mediaAccount.id}" name="id" id="id">
            <div class="layui-form-item layui-form-text">
                <label class="layui-form-label">头像</label>
                <div class="layui-input-block">
                    <button type="button" name="headImg" class="layui-btn" id="headImg">
                        <i class="layui-icon">&#xe67c;</i>上传头像
                    </button>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label required">账号名</label>
                <div class="layui-input-block">
                    <input type="text" name="username" id="username" value="${mediaAccount.username}" lay-verify="required" lay-reqtext="账号名不能为空" placeholder="请输入账号名" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label required">姓名</label>
                <div class="layui-input-block">
                    <input type="text" name="accountName" id="accountName" value="${mediaAccount.accountName}" lay-verify="required" lay-reqtext="姓名不能为空" placeholder="请输入姓名" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label required">帐号详情url</label>
                <div class="layui-input-block">
                    <input type="text" name="url" id="url" value="${mediaAccount.url}" lay-verify="required" lay-reqtext="帐号详情url不能为空" placeholder="请输入帐号详情url" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">账号归属</label>
                <div class="layui-input-inline">
                    <div class="layui-input-inline">
                        <select name="owner" id="owner" lay-verify="required" lay-search="">
                            <option value="0" checked>请选择</option>
                            <option value="1" <c:if test="${mediaAccount.owner == 1}"> selected</c:if>>平台</option>
                            <option value="2" <c:if test="${mediaAccount.owner == 2}"> selected</c:if>>个人</option>
                        </select>
                    </div>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">账号详情图片</label>
                <div class="layui-input-block">
                    <textarea id="detailImg" name="detailImg" style="display: none;">${mediaAccount.detailImg}</textarea>
                </div>
            </div>

            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认保存</button>
                </div>
            </div>
        </div>
    </div>
</div>
<script src="/layui/lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script src="/layui/js/lay-config.js?v=1.0.4" charset="utf-8"></script>

<script>
    layui.use(['form', 'upload', 'layedit'], function () {
        var form = layui.form,
            layer = layui.layer,
            upload = layui.upload,
            layedit = layui.layedit,
            $ = layui.$;

        // 富文本
        layedit.set({
            uploadImage: {
                url: '/apply/file', //接口url
                type: 'post' //默认post
            }
        });

        // 上传头像
        var uploadInst = upload.render({
            elem: '#headImg', //绑定元素
            url: '/apply/files', //上传接口
            done: function(res){
                //上传完毕回调
                // if (res.code == '0') {
                //     window.location = '/indexTwo';
                // }
            },
            error: function(){
                //请求异常回调
            }
        });

        let htmlTag = layedit.build('detailImg'); //建立编辑器

        //监听提交
        form.on('submit(saveBtn)', function (data) {
            var username = $("#username").val();
            var accountName = $("#accountName").val();
            var url = $("#url").val();
            var owner = $("#owner").val();
            var id = $("#id").val();
            $.ajax({
                url: '/apply/modification',
                type: 'post',
                data: {"detailImg": layedit.getContent(htmlTag), "username": username, "accountName": accountName, "url": url,
                    "owner": owner, "id": id},
                <%--"id": ${id}, "price": ${price}--%>
                dataType: 'json',
                success: function (result) {
                    if (result.code == '0') {
                        window.location = '/indexTwo';
                    }
                }
            });
            return false;
        });
    });
</script>
<%--<script>--%>
<%--    layui.use(['form','miniTab'], function () {--%>
<%--        var form = layui.form,--%>
<%--            layer = layui.layer,--%>
<%--            miniTab = layui.miniTab;--%>

<%--        //监听提交--%>
<%--        form.on('submit(saveBtn)', function (data) {--%>
<%--            var index = layer.alert(JSON.stringify(data.field), {--%>
<%--                title: '最终的提交信息'--%>
<%--            }, function () {--%>
<%--                layer.close(index);--%>
<%--                miniTab.deleteCurrentByIframe();--%>
<%--            });--%>
<%--            return false;--%>
<%--        });--%>

<%--    });--%>
<%--</script>--%>
</body>
</html>
